package com.bill99.golden.inf.sso.controller;

import com.bill99.golden.inf.sso.service.TokenService;
import com.bill99.golden.inf.sso.util.CM;
import com.bill99.golden.inf.sso.util.Statistics;
import com.opensymphony.xwork2.ActionContext;
import com.ryan.framework.action.BaseAction;

public class CasPageController extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	
	public String index() throws Exception {
		ActionContext actionContext =this.getActionContext();
		actionContext.put("cCnt", Statistics.getCreateCnt());
		actionContext.put("cMin", Statistics.getCreateMinTime());
		actionContext.put("cMax", Statistics.getCreateMaxTime());
		actionContext.put("cTotal", Statistics.getCreateTotalTime());
		long cAvg = Statistics.getCreateCnt() > 0 ? Statistics.getCreateTotalTime() / Statistics.getCreateCnt() : 0;
		actionContext.put("cAvg", cAvg);
		actionContext.put("vCnt", Statistics.getValidateCnt());
		actionContext.put("vMin", Statistics.getValidateMinTime());
		actionContext.put("vMax", Statistics.getValidateMaxTime());
		actionContext.put("vTotal", Statistics.getValidateTotalTime());
		long vAvg = Statistics.getValidateCnt() > 0 ? Statistics.getValidateTotalTime() / Statistics.getValidateCnt() : 0;
		actionContext.put("vAvg", vAvg);

		actionContext.put("dCnt", Statistics.getDestroyCnt());
		actionContext.put("dMin", Statistics.getDestroyMinTime());
		actionContext.put("dMax", Statistics.getDestroyMaxTime());
		actionContext.put("dTotal", Statistics.getDestroyTotalTime());
		long dAvg = Statistics.getDestroyCnt() > 0 ? Statistics.getDestroyTotalTime() / Statistics.getDestroyCnt() : 0;
		actionContext.put("dAvg", dAvg);

		actionContext.put("sessionCount", TokenService.getSessionCount());

		actionContext.put("date", CM.formatDate("yyyy-MM-dd HH:mm:ss"));
		return SUCCESS;
	}
/*
	public ModelAndView index(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView m = new ModelAndView(this.indexView);
		m.addObject("cCnt", Statistics.getCreateCnt());
		m.addObject("cMin", Statistics.getCreateMinTime());
		m.addObject("cMax", Statistics.getCreateMaxTime());
		m.addObject("cTotal", Statistics.getCreateTotalTime());
		long cAvg = Statistics.getCreateCnt() > 0 ? Statistics
				.getCreateTotalTime() / Statistics.getCreateCnt() : 0;
		m.addObject("cAvg", cAvg);

		m.addObject("vCnt", Statistics.getValidateCnt());
		m.addObject("vMin", Statistics.getValidateMinTime());
		m.addObject("vMax", Statistics.getValidateMaxTime());
		m.addObject("vTotal", Statistics.getValidateTotalTime());
		long vAvg = Statistics.getValidateCnt() > 0 ? Statistics
				.getValidateTotalTime() / Statistics.getValidateCnt() : 0;
		m.addObject("vAvg", vAvg);

		m.addObject("dCnt", Statistics.getDestroyCnt());
		m.addObject("dMin", Statistics.getDestroyMinTime());
		m.addObject("dMax", Statistics.getDestroyMaxTime());
		m.addObject("dTotal", Statistics.getDestroyTotalTime());
		long dAvg = Statistics.getDestroyCnt() > 0 ? Statistics
				.getDestroyTotalTime() / Statistics.getDestroyCnt() : 0;
		m.addObject("dAvg", dAvg);

		m.addObject("sessionCount", TokenService.getSessionCount());

		m.addObject("date", CM.formatDate("yyyy-MM-dd HH:mm:ss"));
		return m;
	}
*/
	public String clear() throws Exception {
		TokenService.checkSessionTimeOut();
		return this.index();
	}

}
